home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / FindIcon / Get_volume_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-21  |  1.9 KB  |  74 lines  |  [TEXT/KAHL]

  1. #include "Get_volume_icon.h"
  2. #include <exceptions.h>
  3. #include "Get_resource_icons.h"
  4. #include "Copy_each_icon.h"
  5.  
  6. /*    ------------------------------------------------------------------
  7.     Get_volume_icon                Create an icon suite for a volume,
  8.                                 assuming that it does not have a custom
  9.                                 icon.
  10.     ------------------------------------------------------------------
  11. */
  12. OSErr    Get_volume_icon(
  13. /* --> */    short    vRefNum,
  14. /* --> */    IconSelectorValue    icon_selector,
  15. /* <-- */    Handle    *the_suite
  16. )
  17. {
  18.     OSErr    err;
  19.     HParamBlockRec    pb;
  20.     ParamBlockRec    cpb;
  21.     Handle            iconHandle;
  22.     short            save_resfile;
  23.     Ptr                *drive_icon;
  24.     
  25.     pb.volumeParam.ioNamePtr = NULL;
  26.     pb.volumeParam.ioVRefNum = vRefNum;
  27.     pb.volumeParam.ioVolIndex = 0;
  28.     
  29.     err = PBHGetVInfoSync(&pb);
  30.     forbid( err, PBHGetVInfoSync );
  31.     
  32.     // set up for Control call
  33.     cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum;
  34.     cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo;
  35.     drive_icon = (Ptr *) &cpb.cntrlParam.csParam;
  36.     *drive_icon = NULL;
  37.     
  38.     // Warning: Under A/UX 3.0, the csCode = 22 call can fail
  39.     // without returning an error code.
  40.     // try media icon
  41.     cpb.cntrlParam.csCode = 22;
  42.     err = PBControlSync( &cpb );
  43.  
  44.     if ( (err != noErr) || ((long)*drive_icon <= 0) )
  45.     {
  46.         // try physical drive icon;
  47.         cpb.cntrlParam.csCode = 21;
  48.         err = PBControlSync( &cpb );
  49.     }
  50.     
  51.     if ( (err == noErr) && (0 < (long)*drive_icon) )    // we got an icon
  52.     {
  53.         err = NewIconSuite( the_suite );    // create the new suite
  54.         forbid( err, NewIconSuite );
  55.         
  56.         err = PtrToHand( *drive_icon, &iconHandle, kLargeIconSize );
  57.         forbid( err, PtrToHand );
  58.  
  59.         err = AddIconToSuite(iconHandle, *the_suite, large1BitMask);
  60.     }
  61.     else    // maybe it's a Mac Plus
  62.     {
  63.         save_resfile = CurResFile();
  64.         UseResFile(0);    // we want a System resource
  65.         err = Get_resource_icons( the_suite, floppyIconResource, icon_selector );
  66.         UseResFile( save_resfile );
  67.     }
  68.  
  69. PtrToHand:
  70. NewIconSuite:
  71. PBHGetVInfoSync:
  72.     return err;
  73. }
  74.